package com.wzg.mytableview.smart;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.DisplayMetrics;

import com.bin.david.form.core.SmartTable;
import com.bin.david.form.data.column.Column;
import com.bin.david.form.data.table.TableData;
import com.wzg.mytableview.R;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * author：wzg
 * date:
 * desc:普通模式
 */
public class DefaultActivity extends AppCompatActivity {


    //获取屏幕的宽度
    private DisplayMetrics displayMetrics = new DisplayMetrics();

    private SmartTable<Material2> table;


    private ArrayList<Material2> material2s = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_default);


        table = findViewById(R.id.smartTable);


        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);


        for (int i = 0; i < 50; i++) {
            material2s.add(new Material2("编号" + i, "10" + i, "" + (10 + i)));
        }

        ArrayList<Column> columns = new ArrayList<>();

        Column<String> materialNo = new Column<String>("物料编号", "materialNo");
        materialNo.setId(3);
        Column<String> num = new Column<String>("入库数", "num");
        materialNo.setId(1);
        Column<String> realNum = new Column<String>("实际入库数", "realNum");
        materialNo.setId(2);

        columns.add(materialNo);
        columns.add(num);
        columns.add(realNum);
        /**进行排序
         *
         */

        Collections.sort(columns, new Comparator<Column>() {
            @Override
            public int compare(Column o1, Column o2) {
                return o1.getId() - o2.getId();
            }
        });


        final TableData<Material2> tableData = new TableData<Material2>("", material2s/*, num, realNum, materialNo*/);
        tableData.setShowCount(false);//不显示统计行
        tableData.setColumns(columns);

        table.getConfig().setShowXSequence(false);
        table.getConfig().setShowYSequence(false);
        table.getConfig().setShowTableTitle(false);//不显示表名
        table.getConfig().setShowColumnTitle(true);
        table.getConfig().setMinTableWidth(displayMetrics.widthPixels);
        table.setTableData(tableData);


    }


}